From f56345bbad359953fbd514aff8a339d55e099804 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Fri, 20 Jun 2014 11:13:33 -0400 Subject: [PATCH] widget factory: Use a property action for the toolbar toggle This is slightly more elegant than doing it manually. --- demos/widget-factory/widget-factory.c | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/demos/widget-factory/widget-factory.c b/demos/widget-factory/widget-factory.c index de9d7d91e9..09b3a09373 100644 --- a/demos/widget-factory/widget-factory.c +++ b/demos/widget-factory/widget-factory.c @@ -38,20 +38,6 @@ change_theme_state (GSimpleAction *action, g_simple_action_set_state (action, state); } -static void -change_toolbar_state (GSimpleAction *action, - GVariant *state, - gpointer user_data) -{ - GtkWidget *window = user_data; - GtkWidget *toolbar; - - toolbar = GTK_WIDGET (g_object_get_data (G_OBJECT (window), "toolbar")); - gtk_widget_set_visible (toolbar, g_variant_get_boolean (state)); - - g_simple_action_set_state (action, state); -} - static void activate_search (GSimpleAction *action, GVariant *parameter, @@ -291,7 +277,6 @@ activate (GApplication *app) GtkAdjustment *adj; static GActionEntry win_entries[] = { { "dark", NULL, NULL, "false", change_theme_state }, - { "toolbar", NULL, NULL, "true", change_toolbar_state }, { "search", activate_search, NULL, NULL, NULL }, { "delete", activate_delete, NULL, NULL, NULL } }; @@ -312,10 +297,13 @@ activate (GApplication *app) widget = (GtkWidget *)gtk_builder_get_object (builder, "statusbar"); gtk_statusbar_push (GTK_STATUSBAR (widget), 0, "All systems are operating normally."); - g_action_map_add_action (G_ACTION_MAP (window), G_ACTION (g_property_action_new ("statusbar", widget, "visible"))); + widget = (GtkWidget *)gtk_builder_get_object (builder, "toolbar"); + g_action_map_add_action (G_ACTION_MAP (window), + G_ACTION (g_property_action_new ("toolbar", widget, "visible"))); + widget = (GtkWidget *)gtk_builder_get_object (builder, "progressbar3"); pulse_id = g_timeout_add (250, (GSourceFunc)pulse_it, widget); g_signal_connect (gtk_builder_get_object (builder, "adjustment1"), -- 2.30.2